<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Controller 
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('Category_model','category');
	}
	
	public function index($id)
	{
		if(($cate = $this->category->get_cat_one($id)) && ($ccate = $this->category->get_children_cat($id)))
		{
			$this->load->view('category/index',array('title'=>$cate['cat_name'].' - 艾木 iMore.cc','ccate'=>$ccate));
		}else{
			show_404();
		}	
	}
	
	public function ccate($id)
	{
		$this->load->model('Goods_model','goods');		
		if(($cate = $this->category->get_cat_one($id)) && ($goods = $this->goods->get_goods_by_cate_id($id)))
		{			
			$all =array();
			$this->load->model('Desc_model','desc');
			$desc = $this->desc->get_desc($id);
			foreach($desc as $des)
			{
				$all[] = array(
						'id' => $des['id'],
						'type' => 'desc',
						'title' =>$des['title'],
						'desc' => $des['desc'],
						'image' => $des['image'],
				);
			}
			foreach($goods as $good)
			{				
				$all[] = array(
					'id' => $good['goods_id'],
					'type' => 'goods',
					'image' => $good['goods_img'],
					'market_price' => $good['market_price'],
					'shop_price' => $good['shop_price'],
					'bargin_price' => $good['bargin_price'],
					'goods_thumb' => $good['goods_thumb'],
				);
			}


			$this->load->view('category/ccate',array('title'=>$cate['cat_name'].' - 艾木 iMore.cc','goods'=>$goods,'all'=>$all));			
		}else{
			show_404();
		}		
	}
}

/* End of file Category.php */
/* Location: ./application/controllers/Category.php */